/////////////////////////////////////////////////////////////////////////////////
//
// Photoshop PSD FileType Plugin for Paint.NET
// http://psdplugin.codeplex.com/
//
// This software is provided under the MIT License:
//   Copyright (c) 2006-2007 Frank Blumenberg
//   Copyright (c) 2010-2012 Tao Yue
//
// Portions of this file are provided under the BSD 3-clause License:
//   Copyright (c) 2006, Jonas Beckeman
//
// See LICENSE.txt for complete licensing and attribution information.
//
/////////////////////////////////////////////////////////////////////////////////

using System;

namespace PhotoshopFile
{
    /// <summary>
    /// Summary description for ResolutionInfo.
    /// </summary>
    internal class GuideLineInfo : ImageResource
    {
        public override ResourceID ID
        {
            get { return ResourceID.GridGuidesInfo; }
        }

        public uint version { get; set; }
        public uint row_num { get; set; }
        public uint col_num { get; set; }
        public uint all_num { get; set; }
        public float[] simpleCoord = new float[2];
        public SingleGuide[] SingleGuideList;
        public class SingleGuide
        {
            public float cor { get; set; }
            public byte lineType { get; set; } // 参考线类型,0为垂直网格线,1为水平网格线
        }

        // public int cor { get; set; }
        // public int col_num { get; set; }

        public GuideLineInfo() : base(String.Empty)
        {
        }

        public GuideLineInfo(PsdBinaryReader reader, string name, int resourceDataLength)
            : base(name)
        {
            var endPosition = reader.BaseStream.Position + resourceDataLength;

            this.version = reader.ReadUInt32();
            this.row_num = reader.ReadUInt32();
            this.col_num = reader.ReadUInt32();
            this.all_num = reader.ReadUInt32();
            if (this.all_num <= 0)
            {
                return;
            }
            SingleGuideList = new SingleGuide[all_num];
            int index = 0;
            while (reader.BaseStream.Position < endPosition)
            {
                float _cor = (reader.ReadUInt32() >> 5); // 读取之后要转成小数，右移5位
                byte _lineType = reader.ReadByte();
                SingleGuideList[index] = new SingleGuide()
                {
                    cor = _cor,
                    lineType = _lineType
                };
                index++;
                if (_lineType == 0)
                {
                    simpleCoord[0] = _cor;
                }
                else if (_lineType == 1)
                {
                    simpleCoord[1] = _cor;
                }
            }

        }

    }
}
